<template>
  <basic-dialog :visible="show"
                title="操作记录"
                :isShowInnerLoading="isShowInnerLoading"
                min-width="1000px"
                isShowClose
                @close="$emit('close')"
  >
    <div class="page-content margin-t-20 ">
      <q-table :data="tableData"
               :columns="columns"
               row-key="id"
               class="myTable scroll stick-to-top inherit"
               :loading="isTableLoading"
               :pagination.sync="pagination"
               style="max-height: 400px"
               :hide-bottom="tableData.length > 0"
               color="primary">
        <template v-slot:body-cell-time="props">
          <q-td :props="props">
            {{props.row.time | toTime}}
          </q-td>
        </template>
      </q-table>
      <yz-pagination v-model="pagination" @onSearch="getList"/>
    </div>
  </basic-dialog>
</template>

<script>
// import _ from 'lodash'
import { getOperationRecord } from 'src/boot/tool/tool-code'
export default {
  name: 'record-dialog',
  components: {
  },
  props: {
    show: Boolean
  },
  data () {
    return {
      isShowInnerLoading: false,
      isTableLoading: false,
      tableData: [],
      pagination: {
        pageNum: 1, // 当前页码
        pageSize: 15, // 每页条数
        rowsNumber: 0 // 总条数
      },
      columns: [
        { name: 'time', label: '操作时间', align: 'left', field: 'time' },
        { name: 'content', label: '操作内容', align: 'left', field: 'content' },
        { name: 'operator', label: '操作人', align: 'left', field: 'operator' }
      ]
    }
  },
  watch: {
    show (newPro) {
      newPro && this.init()
    }
  },
  methods: {
    init () {
      this.pagination.pageNum = 1
      this.tableData = []
      this.getList()
    },
    getList () {
      this.isTableLoading = true
      const params = {
        ...this.pagination,
        toolCategoryCode: this.$attrs.toolCategoryCode
      }
      getOperationRecord(params).then((result) => {
        this.isTableLoading = false
        const ret = result.data
        this.tableData = this.$utils.setLabel(ret.records, { column: this.columns })
        this.pagination.rowsNumber = ret.total
      }).catch((err) => {
        this.isTableLoading = false
        console.log(err)
      })
    }
  }
}
</script>

<style scoped lang="scss">
</style>
